<!-- 批量移动功能，暂时没用 -->
<div class="move-link-tpl" style="display: none;">
    <div class="book-item">
        <a class="move-link" data-id="[[item.id]]" data-parent="[[item.parent_id]]">
                <i class="fa [[item.icon]] fa-[[item.icon]] black"></i>                
                <span>[[item.name]]</span>
                <span class="black">([[item.size]])</span>
        </a>
    </div>
</div>

<div class="move-parent-tpl" style="display: none;">
    <div class="book-item">
        <a class="move-link" data-id="[[item.id]]">
            <i class="fa fa-folder orange"></i>                
            <span>上级目录</span>
        </a>
    </div>
</div>


<script type="text/javascript">
$(function () {
    function buildFolderLink(item) {
        var tpl = $(".move-link-tpl").html();
        tpl = tpl.replace("[[item.name]]", item.name);
        tpl = tpl.replace("[[item.icon]]", item.icon);
        tpl = tpl.replace("[[item.size]]", item.size);
        tpl = tpl.replace(/\[\[item\.id\]\]/gi, item.id);
        tpl = tpl.replace("[[item.parent_id]]", item.parent_id);

        return $(tpl);
    }

    function fetchGroupList(parentId) {
        $.get("/note/api/group?id=" + parentId, function (resp) {
            console.log(resp);
            $(".note-group-select").html("");

            var tpl = $(".move-parent-tpl").html();
            tpl = tpl.replace("[[item.id]]", resp.parent_id);
            var element = $(tpl);
            $(".note-group-select").append(element);

            for (var i = 0; i < resp.data.length; i++) {
                var item = resp.data[i];
                // console.log(item);
                var element = buildFolderLink(item);
                $(".note-group-select").append(element);
            }
        });
    }

    $("body").on("click", ".move-link", function (e) {
        var id = $(this).attr("data-id");
        fetchGroupList(id);
    });

    $("body").on("click", ".do-move-btn", function (e) {
        var parentId = $(this).attr("data-id");

        // 使用callback函数
        callbackFn(parentId);
    });

    window.requestMoveNote = function (callback) {
        if (isMobile()) {
          var area = ['100%', '100%'];
        } else {
          var area = ['600px', '80%'];
        }

        var respHtml = '<div class="note-group-select col-md-12 scroll-y"></div>';
        layer.open({
          type: 1,
          title: "移动笔记",
          shadeClose: true,
          area: area,
          content: respHtml,
          scrollbar: false
        });

        fetchGroupList(0);
        callbackFn = callback;
    }
})
</script>